package com.hand.chenzhuo;

import io.swagger.models.auth.In;

import java.util.*;

public class AliTest {
    public static void main (String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("操作系统",1);
        map.put("计算机网络",2);
        map.put("组成原理",3);
        map.put("数据结构",4);

        //通过for-entrySet进行遍历
        for (Map.Entry<String,Integer> entry : map.entrySet()) {
            System.out.print("entry.getKey() = " + entry.getKey()+"   entry.getValue() = ");
            System.out.println(entry.getValue());
        }

        //通过foreach进行遍历
        for (String key : map.keySet()) {
            System.out.println(key);
        }
        for (Integer value : map.values()) {
            System.out.println("value = " + value);
        }

        //iterator进行遍历
        Iterator<Map.Entry<String,Integer>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            System.out.println("iterator.next().getKey() = " + iterator.next().getKey());
        }
    }
}
